#include "BasicObject.h"

void BasicObject::readFromXML(xmlpp::Node* node)
{
	if(node)
	{
		xmlpp::Node::NodeList list = node->get_children();
		for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
		{
			Glib::ustring nodename = (*iter)->get_name();
			if(nodename == "parent")
			{

			}

			else if(nodename == "parameter")
			{
				const xmlpp::Element* nodeElement = dynamic_cast<const xmlpp::Element*>(node);
				xmlpp::Attribute* attribute = nodeElement->get_attribute("type");
				std::string type = attribute->get_value();
				attribute = nodeElement->get_attribute("type");
				std::string name = attribute->get_value();
				attribute = nodeElement->get_attribute("type");
				std::string value = attribute->get_value();
				Parameter p(type,name,value);
				parameters.push_back(p);
			}
		}

	}
}

unsigned long BasicObject::getID()
{
	return id;
}

void BasicObject::setID(unsigned long id)
{
	this->id = id;
}

unsigned long BasicObject::generateID(const std::vector<BasicObject*> &list)
{
	unsigned long pid = list.size();

	bool eligible = true;
	do
	{
		eligible = true;
		for(unsigned long i = 0; i < list.size(); i++)
		{
			eligible = eligible && (list[i]->getID() != pid);
		}
		pid++;
	}while(!eligible);

	return pid;
}

void BasicObject::construct(std::vector<BasicObject*> &list)
{
	for(unsigned i = 0; i < parentIDs.size(); i++)
	{
		for(unsigned j = 0; j < list.size(); j++)
		{
			if(parentIDs[i] == list[j]->getID())
			{
				parents.push_back(list[j]);
				break;
			}
		}
	}
}

BasicObject::~BasicObject()
{
}



